# -*- coding: utf-8 -*-
import requests
import re
import sys
from PyQt5.QtWidgets import QApplication,QWidget
import winsound
import time
import random

# 监控所长有没有新的回血
#Referer里面不能有汉字
headers={"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36",'content-type': 'charset=utf8',"Referer": "https://zzpcgfd.taobao.com/search.htm?spm=a1z10.3-c.w4002-18761619815.9.69f82dd1k36k4J&_ksTS=1597637084414_132&callback=jsonp133&mid=w-18761619815-0&wid=18761619815&path=%2Fsearch.htm&search=y&orderType=newOn_desc&pageNo=1","Cookie": "t=cac8fc682393fe30f5908415d5cc6f06; cna=LDGxF3ldAxoCAXnhLBWXRsib; miid=1929520071758470797; cookie2=1097081be0d2b5a132c93a9a1d5f0cd1; v=0; _tb_token_=e1896985573b3; _samesite_flag_=true; sgcookie=EuIDZ7zktn60JYfix83tC; uc3=id2=Uoe9bf4Lggp50A%3D%3D&lg2=WqG3DMC9VAQiUQ%3D%3D&nk2=F5REO%2By4rPvwMA%3D%3D&vt3=F8dCufTEVUWktalq8dE%3D; csg=6315c44b; lgc=tb15412616; dnk=tb15412616; skt=dedf76f514d9ab6c; existShop=MTU5NzYzMjUwMA%3D%3D; uc4=nk4=0%40FY4PaQ6E%2B%2FKqcrT%2BaQNyDaKFE0L9&id4=0%40UO%2B7bT45GmCRR8BQdKO1okGi9RYC; tracknick=tb15412616; _cc_=UIHiLt3xSw%3D%3D; enc=ZQsZM4gUkDqOEPs2fvf3CK3xALf71WHQBM8RE2defX0nfXcOdTsiUss0JNNsUp2JFSRiySWCnszMYgn6EefiOw%3D%3D; mt=ci=82_1; thw=cn; hng=CN%7Czh-CN%7CCNY%7C156; _m_h5_tk=7e4bfe1b43b203ddb622d97e20966c02_1597659412122; _m_h5_tk_enc=6ec179ffa3c616d88f7cb430b7c645a1; uc1=pas=0&cookie16=UIHiLt3xCS3yM2h4eKHS9lpEOw%3D%3D&cookie21=U%2BGCWk%2F7p4mBoUyS4E9C&existShop=false&cookie14=UoTV6y%2BG2w7B2A%3D%3D; pnm_cku822=098%23E1hv0pvUvbpvUvCkvvvvvjiPnLSO0jiUP2s9gj3mPmPptj3vn25WQj3CPFsWgjtWiQhvCvvv9UUtvpvhvvvvvvGCvvpvvPMMmphvLCCQQ9vj8Tc6D70OV16ksW2WQC0ww62y%2BneYr2E9ZRAn3w0AhjHVTWex6fItb9TlKWjxKLBI7wLZQW9OecHmQ8oQrBwgnZ43IWoyHd4ivpvUvvmvKfAqCaJEvpvVmvvC9j3bKphv8vvvvvCvpvvvvvmmvhCvvHIvvUUvphvW9vvv99CvpvFFvvmmvhCvmRWCvpvVvmvvvhCv; tfstk=cH11BVjtEcm1R4eq_Naeb0oiKFOfZAoB-RtF598pSCAmK3b1iNGyVh0PnDGpee1..; l=eBQ_OnVcOMupqvQ3BOfwourza77OSIRAguPzaNbMiOCPOI1p5UAFWZuaQ9Y9C3GVhsikR35QyF6TBeYBqIA-LzR40c0LkrHmn; isg=BAUFcUM19r4TNNLhmMehEIp5FEE_wrlU849L3wdqwTxLniUQzxLJJJN4qMJo3tEM"}
rootUrl="https://zzpcgfd.taobao.com/i/asynSearch.htm?_ksTS=1597661202430_132&callback=jsonp133&mid=w-18761619815-0&wid=18761619815&path=/search.htm&search=y&spm=a1z10.3-c.w4002-18761619815.9.69f82dd1k36k4J&orderType=newOn_desc&pageNo=1"
while True :
    #TODO 获取url需要的数字，放在数组里
    response=requests.get(rootUrl,headers=headers)
    response.encoding=response.apparent_encoding#让response自己去解码
    htmlText = response.text
    # print(htmlText)
    pattern = re.compile(r'回血(.*?)</span>件</div>', re.S) #最小匹配
    # pattern = re.compile(r'开车(.*?)</span>件</div>', re.S) #最小匹配
    pageLists=re.findall(pattern,htmlText)
    lengthOfText=len(pageLists)
    print(lengthOfText)
    print(pageLists)
    print(htmlText)
    if lengthOfText>0:
        app=QApplication(sys.argv)
        w=QWidget()
        w.show()
        app.exec_()
        winsound.Beep(370, 2000)
        winsound.Beep(370, 2000)
        winsound.Beep(370, 2000)
    bigSleep = random.randint(30, 60)
    time.sleep(bigSleep)










